package com.mofang.activity.housesource;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.mofang.R;
import com.mofang.activity.BaseTitleViewActiviey;
import com.mofang.adapters.HouseSourceDetailAdapter;
import com.mofang.utils.ListHeightUtils;

import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class HouseSourceDetailActivity extends BaseTitleViewActiviey implements
		OnClickListener {
	private RelativeLayout housingDetails, map, roading_more;
	private ImageView house_pic;
	private TextView total, source_recommend, source_linked;
	ListView listAllHouse;
	HouseSourceDetailAdapter adapter;
	List<Map<String, Object>> list;

	Integer drawable[] = { R.drawable.house_bitmap, R.drawable.house_bitmap,
			R.drawable.house_bitmap };
	String data[] = { "3室2厅2卫——135平米", "3室2厅2卫——135平米", "3室2厅2卫——135平米" };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_source_detail);
		super.onCreate(savedInstanceState);
		setNavigationTitle("房屋详情");
		setNavigationLeftBtnImage(R.drawable.return_arrow);
		initView();
	}

	protected void initView() {
		housingDetails = (RelativeLayout) findViewById(R.id.housing_details);
		housingDetails.setOnClickListener(this);

		map = (RelativeLayout) findViewById(R.id.map);
		map.setOnClickListener(this);

		house_pic = (ImageView) findViewById(R.id.house_pic);
		house_pic.setOnClickListener(this);

		total = (TextView) findViewById(R.id.total);// 户型总数

		roading_more = (RelativeLayout) findViewById(R.id.roading_more);
		roading_more.setOnClickListener(this);

		source_recommend = (TextView) findViewById(R.id.source_recommend);
		source_recommend.setOnClickListener(this);

		source_linked = (TextView) findViewById(R.id.source_linked);
		source_linked.setOnClickListener(this);

		listAllHouse = (ListView) findViewById(R.id.list_all_house);
		addData();
		adapter = new HouseSourceDetailAdapter(HouseSourceDetailActivity.this,
				list);
		listAllHouse.setAdapter(adapter);
		ListHeightUtils.setListViewHeightBasedOnChildren(listAllHouse);

		listAllHouse.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view,
					int position, long arg3) {
				// 户型介绍详情
				Intent intent = new Intent(HouseSourceDetailActivity.this,
						HousePictureActivity.class);
				startActivity(intent);
			}
		});
	}

	private void addData() {
		// TODO Auto-generated method stub
		list = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < drawable.length; i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("data", data[i]);
			map.put("drawable", drawable[i]);
			list.add(map);
		}

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent intent;
		switch (v.getId()) {
		case R.id.housing_details:// 楼盘详情
			intent = new Intent(HouseSourceDetailActivity.this,
					HousingDetailsActivity.class);
			startActivity(intent);
			break;
		case R.id.map:// 地图
			// intent=new
			// Intent(HouseSourceDetailActivity.this,MapActivity.class);
			// startActivity(intent);
			break;
		case R.id.house_pic:// 楼房图片
			intent = new Intent(HouseSourceDetailActivity.this,
					HousePictureActivity.class);
			startActivity(intent);
			break;
		case R.id.roading_more:// 加载全部
			Toast.makeText(getApplicationContext(), "加载更多", Toast.LENGTH_SHORT)
					.show();
			break;
		case R.id.source_recommend:
			// 马上推荐
			break;
		case R.id.source_linked:
			// 立即联系
			break;
		default:
			break;
		}
	}
}
